package com.book.controller;

import com.book.model.entity.BookCategory;
import com.book.service.BookCategoryService;
import com.book.util.BaseResult;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 书本类别 前端控制器
 * </p>
 *
 * @author auto
 * @since 2025-04-02 06:38:55
 */
@RestController
@RequestMapping("/book-category")
@Tag(name = "书本类别", description = "书本类别相关接口")
public class BookCategoryController {

    @Autowired
    private BookCategoryService bookCategoryService;

    @ApiOperation(value = "分页查询书本类别")
    @PostMapping("/list/{page}/{size}")
    public BaseResult<?> getBookCategoryListByPage(@PathVariable("page") Integer page, @PathVariable("size") Integer size, @RequestParam("search") String search) {
        return BaseResult.successResult(bookCategoryService.getBookCategoryListByPage(page, size,search));
    }

    @ApiOperation(value = "查询所有书本类别")
    @GetMapping("/list")
    public BaseResult<?> getBookCategoryList() {
        return BaseResult.successResult(bookCategoryService.getBookCategoryList());
    }

    @ApiOperation(value = "根据id查询书本类别")
    @GetMapping("/getById/{id}")
    public BaseResult<?> getById(@PathVariable("id") String id) {
        return BaseResult.successResult(bookCategoryService.getById(id));
    }

    @ApiOperation(value = "新增图书类别")
    @PostMapping("/add")
    public BaseResult<?> addCategory(@RequestParam("name") String name) {
        return BaseResult.successResult(bookCategoryService.addCategory(name));
    }

    @ApiOperation(value = "删除类别")
    @DeleteMapping("/{id}")
    public BaseResult<?> deleteCategory(@PathVariable("id") String id) {
        return BaseResult.successResult(bookCategoryService.removeById(id));
    }

    @ApiOperation(value = "修改图书类别")
    @PostMapping("/update")
    public BaseResult<?> updateCategory(@RequestBody BookCategory bookCategory) {
        return BaseResult.successResult(bookCategoryService.updateById(bookCategory));
    }
}